import Vue from 'vue'
import Router from 'vue-router'
const _import = require('./_import_' + process.env.NODE_ENV)
// in development env not use Lazy Loading,because Lazy Loading too many pages will cause webpack hot update too slow.so only in production use Lazy Loading

/* layout */
import Layout from '../views/layout/Layout'

Vue.use(Router)

 /**
  * icon : the icon show in the sidebar
  * hidden : if `hidden:true` will not show in the sidebar
  * redirect : if `redirect:noredirect` will not redirct in the levelbar
  * noDropdown : if `noDropdown:true` will not has submenu in the sidebar
  * meta : `{ role: ['admin'] }`  will control the page role
  **/
export const constantRouterMap = [
  { path: '/login', component: _import('login/index'), hidden: true },
  { path: '/404', component: _import('404'), hidden: true },
  {
    path: '/',
    component: Layout,
    redirect: '/index',
    name: '首页',
    hidden: true,
    children: [{ path: 'index', component: _import('index/index') }]
  }
]

export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  {
    path: '/base',
    component: Layout,
    redirect: 'noredirect',
    name: '基础数据',
    icon: 'zujian',
    children: [
      { path: 'warehouse', name: '仓库基础数据维护', icon: 'zonghe', component: _import('base/warehouse') }
    ]
  },
  {
    path: '/table',
    component: Layout,
    redirect: '/table/index',
    icon: 'tubiao',
    noDropdown: true,
    children: [{ path: 'index', name: 'Table', component: _import('table/index'), meta: { role: ['admin'] }}]
  },
  {
    path: '/enterprise',
    component: Layout,
    redirect: 'noredirect',
    name: '企业管理',
    icon: 'qiye',
    children: [
      { path: 'myCompany', name: '我的公司', component: _import('enterprise/myCompany'), meta:{role:['test']}},
      { path: 'customerList', name: '我的客户', component: _import('enterprise/customerList'), meta:{role:['test']}},
      { path: 'supplyList', name: '我的供应商', component: _import('enterprise/supplyList'), meta:{role:['test']}}
    ]
  },
  {
    path: '/customerOrder',
    component: Layout,
    redirect: 'noredirect',
    name: '客户定单',
    icon: 'qiye',
    children: [
      { path: '/customerOrder/quotes',
        name: '报价管理',
        component: _import('customerOrder/quote/quotesIndex'),
        meta: { role: ['test'] },
        redirect: 'noredirect',
        children: [
          { path: 'createCompute', name: '新建核算单', component: _import('customerOrder/quote/createCompute/createCompute'), meta: { role: ['test'] }},
          { path: 'computeList', name: '核算单列表', component: _import('customerOrder/quote/computeList'), meta: { role: ['test'] }},
          { path: 'createQuote', name: '新建报价单', component: _import('customerOrder/quote/createQuote/createQuote'), meta: { role: ['test'] }},
          { path: 'quoteList', name: '报价单列表', component: _import('customerOrder/quote/quoteList'), meta: { role: ['test'] }}
        ]
      },
      { path: '/customerOrder/orders',
        name: '定单管理',
        component: _import('customerOrder/order/ordersIndex'),
        meta: { role: ['test']},
        redirect: 'noredirect',
        children: [
          { path: 'createCstOrder', name: '新建定单', component: _import('customerOrder/order/createCustomerOrder'), meta: { role: ['test'] }},
          { path: 'cstOrderList', name: '定单列表', component: _import('customerOrder/order/cstOrderList'), meta: { role: ['test'] }},
          { path: 'orderStartup', name: '订单下达', component: _import('customerOrder/order/orderStartup'), meta: { role: ['test'] }}
        ]
      }
    ]
  },
  {
    path: '/materials',
    component: Layout,
    redirect: 'noredirect',
    name: '物料管理',
    icon: 'qiye',
    children: [
      { path: 'bomList', name: 'BOM列表', component: _import('materials/bomList'), meta:{role:['test']}},
      { path: 'editBOM', name: 'BOM创建', component: _import('materials/editBOM'), meta:{role:['test']}}
    ]
  },
  {
    path: '/purchase',
    component: Layout,
    redirect: 'noredirect',
    name: '采购管理',
    icon: 'qiye',
    children: [
      { path: '/purchase/request',
        name: '请购单管理',
        component: _import('purchase/request/reqIndex'),
        meta: { role: ['test'] },
        redirect: 'noredirect',
        children: [
          { path: 'createRequest', name: '新建请购单', component: _import('purchase/request/createRequest'), meta:{role:['test']}},
          { path: 'reqList', name: '请购单列表', component: _import('purchase/request/reqList'), meta:{role:['test']}}
        ]
      },
      { path: '/purchase/mrp',
        name: '物料需求计划',
        component: _import('purchase/matRequirePlan/mrpIndex'),
        meta: { role: ['test'] },
        redirect: 'noredirect',
        children: [
          { path: 'mrpList', name: '需求计划列表', component: _import('purchase/matRequirePlan/matRequirePlanList'), meta:{role:['test']}},
        ]
      },
      { path: '/purchase/inquiry',
        name: '询价单',
        component: _import('purchase/inquiry/inquiryIndex'),
        meta: { role: ['test'] },
        redirect: 'noredirect',
        children: [
          { path: 'inquiryList', name: '询价单列表', component: _import('purchase/inquiry/list/inquiryList'), meta:{role:['test']}},
        ]
      },
      { path: '/purchase/purchase',
        name: '采购单',
        component: _import('purchase/purchase/purchaseOrderIndex'),
        meta: { role: ['test'] },
        redirect: 'noredirect',
        children: [
          { path: 'purchaseList', name: '采购单列表', component: _import('purchase/purchase/purchaseList'), meta:{role:['test']}}
        ]
      },
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]
